package edu.jkd.controller;


import edu.jkd.entity.Customer;
import edu.jkd.entity.Myorder;
import edu.jkd.entity.Product;
import edu.jkd.mapper.CustomerMapper;
import edu.jkd.service.ICustomerService;
import edu.jkd.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;

import static javax.xml.bind.JAXBIntrospector.getValue;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author holyfox
 * @since 2022-11-28
 */
@Controller
public class CustomerController {
    @Autowired //
    private IProductService productService;
    @Autowired
    private ICustomerService customerService;


    @GetMapping("customer")
    public ModelAndView getAllCustomer() {
            ModelAndView mav = new ModelAndView();
        //1. 调用service---mapper ---database 查询
           List<Customer> customerList = customerService.list();
        //2. 数据绑定
            mav.addObject("customerList", customerList);
            mav.setViewName("login");
           return mav;
     }
    //获得所有的商品  http://localhost:8080/demo/product
//    @GetMapping("product")
//    public ModelAndView getAllProduct(){
//        ModelAndView mav = new ModelAndView();
//        //1. 调用service---mapper ---database 查询
//        List<Product> productList = productService.list();
//
//        //2. 数据绑定
//        mav.addObject("productList",productList);
//        //3. 页面跳转
//        mav.setViewName("login");  // index.jsp
//        return mav;
//    }


        @GetMapping("customer/{id}")
        public ModelAndView getById(@PathVariable("id") Integer id){
            Customer customer = customerService.getById(id);
            ModelAndView mav = new ModelAndView("304usercenter");
            mav.addObject("customer",customer);
            mav.setViewName("304usercenter");
            return mav;
        }


//    @GetMapping("product/{id}")
//    public ModelAndView getById(@PathVariable("id") Integer id){
//        Product product = productService.getById(id);
//        ModelAndView mav = new ModelAndView("304usercenter");  // /detail.jsp
//        mav.addObject("product",product);
//        return mav;
//
//    }
//


    @GetMapping("index/{id}")
    public ModelAndView getPicture(Integer id){
        id=1;

        Customer customer=customerService.getById(id);
        ModelAndView mav=new ModelAndView("indexlogin");
        mav.addObject("customer",customer);
        List<Product> productList = productService.list();
        //2数据绑定
        mav.addObject("productList", productList);

        return mav;
    }

















}
